<?php

declare(strict_types=1);

namespace App\Request\Api\Auth;

use Hyperf\Validation\Request\FormRequest;

class UserRegisterRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'mobile' => 'required|regex:/^1[123456789]\d{9}$/',
            'invite_code' => 'required|exists:users,invite_code',
            // 8-16个字符 数字 + 字母
            'password' => 'required|regex:/^(?![\d]+$)(?![a-z]+$)(?![A-Z]+$)(?![!#$%^&*]+$)[\da-zA-Z-!@#$^&+.]{8,32}$/',
        ];
    }

    public function messages(): array
    {
        return [
            'mobile.regex' => '手机号码必须为11位数字组成',
            'password.regex' => '密码为8-16位数字_字母组成',
            'invite_code.required' => '邀请码必填',
            'invite_code.exists' => '邀请码不正确',
        ];
    }
}
